package org.edu.modules.classSchedule.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.edu.common.api.vo.Result;
import org.edu.common.system.query.QueryGenerator;
import org.edu.common.util.oConvertUtils;
import org.edu.modules.classChoise.service.IJwKechengClassService;
import org.edu.modules.jxrw.entity.VeJwJxrw;
import org.edu.modules.jxrw.service.IVeJwJxrwService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.edu.common.system.base.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.edu.common.aspect.annotation.AutoLog;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @Description: 教学任务
 * @Author:
 * @Date:   2021-05-20
 * @Version: V1.0
 */
@Api(tags="排课信息明细")
@RestController
@RequestMapping("/classSchedule/veJwJxrw")
@Slf4j
public class VeJwJxrwClassController extends BaseController<VeJwJxrw, IVeJwJxrwService> {
	@Autowired
	private IVeJwJxrwService veJwJxrwService;
	@Autowired
	private IJwKechengClassService iJwKechengClassService;
	/**
	 * 分页查询
	 * @param veJwJxrw
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "教学任务-排课任务课程查询")
	@ApiOperation(value="排课任务课程查询", notes="教学任务-排课任务课程查询")
	@PostMapping(value = "/rwkcList")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "semid", value = "学期id", required = true),
			@ApiImplicitParam(name = "jxbid", value = "教学班id", required = true)
	})
	public Result<?> queryPageList(@ApiIgnore VeJwJxrw veJwJxrw,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="99") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<VeJwJxrw> queryWrapper = QueryGenerator.initQueryWrapper(veJwJxrw, req.getParameterMap());
		Page<Map<String,Object>> page = new Page<Map<String,Object>>(pageNo, pageSize);
		IPage<Map<String,Object>> pageList = veJwJxrwService.pageMaps(page, queryWrapper);
		List<Map<String, Object>> veJwJxrws = pageList.getRecords();
		for (Map<String,Object> map : veJwJxrws){
			Integer kcid = Integer.parseInt(map.get("kcid").toString());
			String kcmc = iJwKechengClassService.selectCourseNameById(kcid);
			map.put("kcmc", kcmc);
		}
		pageList.setRecords(veJwJxrws);
		return Result.OK(pageList);
	}

//	/**
//	* 通过id查询
//	* @param id
//	* @return
//	*/
//	@AutoLog(value = "教学任务-通过id查询")
//	@ApiOperation(value="通过id查询", notes="教学任务-通过id查询")
//	@PostMapping(value = "/queryById")
//	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
//		VeJwJxrw veJwJxrw = veJwJxrwService.getById(id);
//		if(veJwJxrw==null) {
//			return Result.error("未找到对应数据");
//		}
//		return Result.OK(veJwJxrw);
//	}

//	/**
//	 * 新增信息
//	 * @param veJwJxrw
//	 * @return
//	 */
//	@AutoLog(value = "教学任务-新增信息")
//	@ApiOperation(value="新增信息", notes="教学任务-新增信息")
//	@PostMapping(value = "/add")
//	public Result<?> add(@RequestBody VeJwJxrw veJwJxrw) {
//		if(veJwJxrwService.save(veJwJxrw)){
//		   return Result.OK("添加成功！");
//        }
//        return Result.error("添加失败!");
//	}
//
//	/**
//	 * 修改信息
//	 * @param veJwJxrw
//	 * @return
//	 */
//	@AutoLog(value = "教学任务-修改信息")
//	@ApiOperation(value="修改信息", notes="教学任务-修改信息")
//	@PostMapping(value = "/edit")
//	public Result<?> edit(@RequestBody VeJwJxrw veJwJxrw) {
//        if(veJwJxrwService.updateById(veJwJxrw)){
//		    return Result.OK("编辑成功!");
//        }
//        return Result.error("编辑失败!");
//	}
//
//	/**
//	 * 通过id删除
//	 * @param id
//	 * @return
//	 */
//	@AutoLog(value = "教学任务-通过id删除")
//	@ApiOperation(value="通过id删除", notes="教学任务-通过id删除")
//	@PostMapping(value = "/delete")
//	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
//        if(veJwJxrwService.removeById(id)){
//		    return Result.OK("删除成功!");
//        }
//        return Result.error("删除失败!");
//	}
//
//	/**
//	 * 批量删除
//	 * @param ids
//	 * @return
//	 */
//	@AutoLog(value = "教学任务-批量删除")
//	@ApiOperation(value="批量删除", notes="教学任务-批量删除")
//	@PostMapping(value = "/deleteBatch")
//	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
//		if(this.veJwJxrwService.removeByIds(Arrays.asList(ids.split(",")))){
//		         return Result.OK("批量删除成功!");
//        }
//        return Result.error("批量删除失败!");
//	}

}
